package com.wxapp.admin.service.controller;

import com.wxapp.admin.api.pojo.vm.menu.PMenuBaseVm;
import com.wxapp.admin.api.pojo.vm.menu.PMenuSelectVm;
import com.wxapp.admin.api.pojo.vm.menu.PMenuTreeSelectVm;
import com.wxapp.admin.api.pojo.vm.menu.PMenuTreeVm;
import com.wxapp.admin.api.pojo.vo.menu.QAddMenuVo;
import com.wxapp.admin.api.pojo.vo.menu.QMenuListVo;
import com.wxapp.admin.api.pojo.vo.menu.QMenuUpdateVo;
import com.wxapp.admin.service.service.MenuService;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @Description 菜单类
 * @Datetime 2022/7/30 13:58
 * @Modified By
 */
@RestController
@RequestMapping("menu")
@Tag(name = "权限管理")
@RequiredArgsConstructor
public class MenuController extends IBaseController {
    private final MenuService menuService;

    @GetMapping("menu")
    @Operation(summary ="首页菜单")
    public ResultVm<List<PMenuTreeVm>> menu(@Schema(hidden = true) @User UserVo userVo) {
        return menuService.menu(userVo);
    }

    @PostMapping("list")
    @Operation(summary ="菜单list")
    public ResultVm<List<PMenuTreeVm>> listMenu(@RequestBody QMenuListVo qMenuListVo) {
        return menuService.listMenu(qMenuListVo);
    }

    @GetMapping("detail/{id}")
    @Operation(summary ="菜单明细")
    public ResultVm<PMenuBaseVm> detailMenu(@PathVariable String id) {
        return menuService.detailMenu(id);
    }

    @PostMapping("add")
    @Operation(summary ="添加菜单")
    public ResultVm<String> addMenu(@Schema(hidden = true) @User UserVo userVo, @RequestBody QAddMenuVo qaddMenuVo) {
        return menuService.addMenu(userVo, qaddMenuVo);
    }

    @PutMapping("update")
    @Operation(summary ="修改菜单")
    public ResultVm<String> updateMenu(@Schema(hidden = true) @User UserVo userVo, @RequestBody QMenuUpdateVo qUpdateVm) {
        return menuService.updateMenu(userVo, qUpdateVm);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary ="删除菜单")
    public ResultVm<String> deleteMenu(@Schema(hidden = true) @User UserVo userVo, @PathVariable String id) {
        return menuService.deleteMenu(userVo,id);
    }


    @GetMapping("select")
    @Operation(summary ="获取下拉框菜单列表")
    public ResultVm<List<PMenuSelectVm>> selectMenu(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "type", required = false) String type) {
        return menuService.selectMenu(name, type);
    }

    @GetMapping("treeSelect")
    @Operation(summary ="获取下拉框菜单树形列表")
    public ResultVm<List<PMenuTreeSelectVm>> treeSelect(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "roleId", required = false) String roleId) {
        return menuService.treeSelect(name, type, roleId);
    }
}
